﻿using System;
using System.Data.Common;

namespace Com.Lancetinc.Evs.Data
{
    public class NotCloseDbConnection : IDisposable
    {
        private readonly DbConnection conn;
        private int calls = 0;

        public NotCloseDbConnection(DbConnection conn)
        {
            this.conn = conn;
            this.calls = 1;
        }

        public DbTransaction BeginTransaction()
        {
            return conn.BeginTransaction();
        }

        public DbCommand CreateCommand()
        {
            return conn.CreateCommand();
        }

        public void IncreaseCalls()
        {
            calls++;
        }

        public void Dispose()
        {
            calls--;
        }

        internal void ForceClose()
        {
            conn.Close();
        }
    }
}
